package weekMatch.one_337;

public class LeeCode_03_02 {
    private int ans = -1, k;
    private int[] cnt, nums;

    public int beautifulSubsets(int[] nums, int k) {
        this.nums = nums;
        this.k = k;
        cnt = new int[k * 2 + 1001];
        dfs(0);
        return ans;
    }

    private void dfs(int i){
        if (i == nums.length){
            ans++;
            return;
        }
        dfs(i + 1);
        int x = nums[i] + k;
        if (cnt[x + k] == 0 && cnt[x - k] == 0){
            ++cnt[x];
            dfs(i + 1);
            --cnt[x];
        }
    }
}
